#include <QCoreApplication>
#include <QDir>
#include <QSettings>
#include "standard-paths.h"

QString StandardPaths::m_configPath;
QString StandardPaths::m_dataPath;
QString StandardPaths::m_imagesPath;
QString StandardPaths::m_translationsPath;

QString StandardPaths::configPath()
{
    if (m_configPath.isEmpty())
        m_configPath = dataPath() + "config.ini";

    return m_configPath;
}

QString StandardPaths::dataPath()
{
    if (m_dataPath.isEmpty())
    {
#ifdef DEVELOPMENT_BUILD
        m_dataPath = QCoreApplication::applicationDirPath() + "/data/";
#else
#ifdef Q_OS_WIN
        // hack to get %APPDATA% path on Windows
        // we can't use QDesktopServices, because it requires QtGui module
        QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::applicationName(), "config.ini");
        m_dataPath = QFileInfo(settings.fileName()).absolutePath() + "/";
#elif Q_OS_LINUX || Q_OS_MAC
        m_dataPath = QDir::homePath() + "/.config/" + QCoreApplication::applicationName() + "/";
#else
        m_dataPath = QCoreApplication::applicationDirPath() + "/data/";
#endif // Q_OS_*
#endif // DEVELOPMENT_BUILD
    }

    return m_dataPath;
}

QString StandardPaths::imagesPath()
{
    if (m_imagesPath.isEmpty())
        m_imagesPath = ":/images/";

    return m_imagesPath;
}

QString StandardPaths::translationsPath()
{
    if (m_translationsPath.isEmpty())
        m_translationsPath = QCoreApplication::applicationDirPath() + "/translations/";

    return m_translationsPath;
}
